import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:interview/config/app.enum.dart';
import 'package:interview/controller/user_controller.dart';
import 'package:interview/utils/logger.dart';

class ClockIn extends StatelessWidget {
  const ClockIn({super.key});

  void tapHandle () {
    Logger.info("点击打卡" , tag: "ClockIn");
  }
  @override
  Widget build(BuildContext context) {

    return GestureDetector(
      onTap:()=> tapHandle() ,
      child: Container(
        padding: const EdgeInsets.only(left: 26, top: 12 , bottom: 10 , right: 6),
        decoration: const BoxDecoration(
          image: DecorationImage(
            image:AssetImage('${AppEnumAssets.basePath}ic_common_clocked.png'),
            fit: BoxFit.contain)
          ),
        child: Center(
          child:GetX<UserController>(
            builder: (userController){
              final user = userController.getUser();
              // 提取 clockinNumbers 或默认值 0
              final clockinDays = user?.clockinNumbers ?? 0;
              // 为空时显示默认内容
              final clockinText = clockinDays > 0? '${user?.clockinNumbers ?? 0} 天' : '打卡';
              final subText = clockinDays > 0? '本月打卡' : '';
              return Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  if (subText.isNotEmpty)
                    Text(subText, style: const TextStyle(fontSize: 8, color: Colors.black)),
                  Text(
                    clockinText,
                    style: const TextStyle(fontSize: 10, color: Colors.black, fontWeight: FontWeight.bold),
                  ),
                ],
              );
            },
          )
        )
      )
    ) ;
  }
}
